from rest_framework import serializers, viewsets
from api.models import Snippet, LANGUAGE_CHOICES, STYLE_CHOICES


class SnippetSerializer(serializers.ModelSerializer):
    owner = serializers.ReadOnlyField(source='owner.username')  # source用于指定字段显示外键关联对象的字段
    title = serializers.CharField(source="owner.username")

    class Meta:
        model = Snippet
        # fields = ('id', 'title', 'code', 'linenos', 'language', 'style', "owner")
